<template>
  <van-icon
    @click="loadaddLike"
    :color="value === 1 ? 'red' : '#777'"
    :name="value === 1 ? 'good-job' : 'good-job-o'"
    :loading="loading"
  />
</template>

<script>
import { addLike, deleteLike } from '@/api/article'
export default {
  name: 'LikeArticle',
  props: {
    value: {
      type: [Number, String],
      require: true
    },
    ArticleId: {
      type: [Number, String, Object],
      require: true
    }
  },
  data () {
    return {
      loading: false
    }
  },
  methods: {
    async loadaddLike () {
      this.loading = true
      try {
        let status = -1
        if (this.value === 1) {
          await deleteLike(this.ArticleId)
        } else {
          await addLike(this.ArticleId)
          status = 1
        }
        this.$emit('input', status)
        this.$toast.success(this.status === 1 ? '点赞成功' : '取消点赞')
      } catch (err) {
        this.$toast.fail('点赞失败')
      }
      this.loading = false
    }
  }
}
</script>
<style lang="less" scope>
</style>
